﻿define(function(require, exports, module) {

    var layout = require("modules/layout/index.js");
    var sideTree = require("modules/side-tree/index.js");
    var multiPage = require("modules/multi-page/index.js");

    var _ = require('lib/lodash.js');


    window.vueApp = new Vue({
        el: '#app',
        data: {
            innerPage: {
                pages: [{
                    menuName: '文章列表',
                    level: 1,
                    url: 'page/ArticleList.html',
                    iconCls: 'fa-bullseye',
                    collapsed: false,
                    active: true,
                    children: []
                }],
                hasTop: true
            },
            isCollapse: true,
            tree: [{
                menuName: '网站管理',
                level: 1,
                iconCls: 'fa-cube',
                collapsed: false,
                active: false,
                children: [{
                    menuName: '接口动态化',
                    level: 2,
                    iconCls: 'fa-database',
                    active: false,
                    url: 'page/dmlList.html',
                },{
                    menuName: '栏目管理',
                    level: 1,
                    url: 'page/categoryList.html',
                    iconCls: 'fa-paper-plane',
                    collapsed: false,
                    active: false,
                    children: []
                }, {
                    menuName: '文章列表',
                    level: 1,
                    url: 'page/ArticleList.html',
                    iconCls: 'fa-bookmark',
                    collapsed: false,
                    active: false,
                    children: []
                },{
                    menuName: '网页配置',
                    level: 1,
                    url: 'page/pageConfigList.html',
                    iconCls: 'fa-chrome',
                    collapsed: false,
                    active: false,
                    children: []
                },{
                    menuName: '图片列表',
                    level: 1,
                    url: 'page/PicList.html',
                    iconCls: 'fa-file-image-o',
                    collapsed: false,
                    active: false,
                    children: []
                }
                ]
            }],
            defaultProps: {
                children: 'children',
                label: 'label'
            }
        },
        methods: {},
        mounted: function() {
            $(window).bind("load resize", this.myResize);
            setTimeout(this.myResize, 0);
        },
        events: {},
        methods: {
            innerPageAdd: function(node) {
                if (node.open_type != null && node.open_type == "newWin") {
                    window.open(node.url);
                    return;
                }

                if (!this.innerPage.hasTop) {
                    this.innerPage.pages = [];
                    node["active"] = true;
                    this.innerPage.pages.push(node);
                }

                var hasIn = false;
                _.forEach(this.innerPage.pages, function(page) {
                    if (page.menuName == node.menuName) {
                        page.active = true;
                        hasIn = true;
                    } else {
                        page.active = false;
                    }

                });


                if (!hasIn) {
                    node["active"] = true;
                    this.innerPage.pages.push(node);
                }


            },
            innerPageMove: function(node) {
                var hasIn = false;
                this.innerPage.pages = _.remove(this.innerPage.pages, function(page) {
                    return page.menuName != node.menuName;
                });

                if (this.innerPage.pages.length > 0) {
                    this.innerPage.pages[this.innerPage.pages.length - 1].active = true;
                }


            },
            myResize: function() {
                var outerWidth = $(window).width();
                var outerHeight = $(window).height();
                $("#app").css({
                    height: outerHeight + 'px'
                });
            },
            toggleHasTop: function(to) {
                if (to == undefined) {
                    this.innerPage.hasTop = !this.innerPage.hasTop;
                } else {
                    this.innerPage.hasTop = to;
                }
            }
        }

    });

});